<?include_once('conn.php');?>
<?include_once('inc_head.php');?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?
$act=$_GET['act'];
$listTable = TABLE_C."vote_qn";

#/////////////////////////删除/////////////////////
if($act=='del') {	
	$id=addslashes($_GET['id']); 
	//从数据数据库
	$cmd="delete from $listTable where id=".$id;
	if(mysql_query($cmd) or die(mysql_error())){
	gourl('删除成功！',$cururl);	
	}
	exit;
}

////////////////////////////////////  复选框批量操作   ///////////////////////////////////////////////
if($act=="doall"){
	 $doact=$_POST['doact'];#子动作
	 $idarr=$_POST['checkbox'];
	  if($_POST['checkbox']==""){gourl("没有选择序列！",$cururl);exit;}#是否有选择
	 $allID=implode(",",$_POST['checkbox']);#处理ID
	 $orderVal=intval($_POST['orderVal']);#排序的值 
	 switch($doact){
		 #批量删除
		 case "del":
			 for($i=0;$i<count($idarr);$i++){
				$id=$idarr[$i];
				echo "<br>处理ID为 $id 的记录:";
				//从数据数据库
				$cmd="delete from $listTable where id=".$id;
				if(mysql_query($cmd) or die(mysql_error())){
					echo "<div class=tipsok>成功从数据库删除</div>";
				}
				#删除结束
			 }
			 echo " 点击 <a href=".$_SESSION['lastUrl'].">这里</a> 返回";
		 break;
	 }
	 exit;
}
?>
<body>
	<?local("公司所属员工的问卷");?>
<div id="intro">
<!-------------------------------------默认状态------------------------------------->
<table width="100%" border="0"  cellpadding="2" cellspacing="0">
  <tr> 
      <td width="50%"> </td>
			
      <td width="50%" align=right> 
	  <?	
	  	// 页友
		$page=intval($_GET['page']);
		if($page==0){$page=1;}
		$pagesize=$news_pagesize;
		$rsStar=$page*$pagesize-$pagesize;

		$cid = $_GET['company'];
		$condition  = "where c.id = $cid";
		

		//排序整理
		$orderTxt="order by $okey";
		if($okey==''){
			$orderTxt='order by c.id desc';
		}
		
		$cmd="
		select 
		qn.*,
		qs.name sname,
		ar.title area_name,
		c.title company_name,c.id cid

		from $listTable qn 
		left join(select * from {$TABLE}vote_series) qs on qs.id = qn.sid 
		left join(select * from {$TABLE}service_area) ar on ar.id = qn.service_area 
		left join(SELECT * from {$TABLE}user) u on qn.unionid = u.unionid 
		left join(select * from {$TABLE}company) c on u.company = c.id 
		 ".$condition." ".$orderTxt;

		//总数

		$rs=mysql_query($cmd) or die(mysql_error());
		$rstotal=mysql_num_rows($rs);

		// 查询的时候，再加上limit
		$cmd .= " LIMIT $rsStar,$pagesize";
		$rs=mysql_query($cmd) or die(mysql_error());	
		
		$pagetotal=ceil($rstotal/$pagesize); //记录总数
		echo "<div>当前分类记录数共【".$rstotal."】条,每页显示【".$pagesize."】条 ,页码：$page/$pagetotal</div>";
		 ?>
	  </td>
          </tr>
        </table>
	<!--主内容表格-->
<form name="form_all" method=post action="?act=doall" style="margin:0px">
  <table class="table table-hover table-bordered table-striped" width="100%" border="0"  cellpadding="0" cellspacing="0" >
    <tr> 
      <th width="70">ID</th>

      <th width="">问卷编号</th>
      <th width="">用户unionid</th>
      <th width="">所属公司</th>
      <th width="">问卷类型</th>
      <th width="">业务区域</th>
      <th width="150">问卷时间</th>

      <th width="150" >操作</th>
    </tr>
    <?
   	showemptyrs($rs);
	while($row=mysql_fetch_assoc($rs)){
	  $id=$row['id'];
  ?>
    <tr  class="mytr" > 
      <td align="center" ><? echo $row['id'] ?></td>

      <td align="" ><? echo $row['qn_no'];?></td>
      <td align="" ><? echo $row['unionid'];?></td>
      <td align="" ><? echo "{$row['company_name']} [{$row['cid']}]";?></td>
      <td align="" ><? echo "{$row['sname']}    [{$row['sid']}]";?></td>
      <td align="" ><? echo "{$row['area_name']}[{$row['service_area']}]";?></td>
      <td align="" ><? echo $row['datetime'];?></td>
	  
      <td align="center" > 
		<a href="admin_vote_report.php?qn=<?echo $row['qn_no']?>" class="btn btn-xs btn-info" rel="floatEdit" target="_blank">问卷报告</a> 
 		<!-- <a  href="javascript:if(confirm('确定吗')){window.location='?act=del&id=<?echo $id?>&vfile=<? echo $row['videofile'];?>&imgf=<?echo $row['imagefile'];?>'}" class="btn btn-xs btn-danger">删除</a>  -->
       </td>
    </tr>
    <?}?>
  </table>

  <!--下面的控制表格-->
  <table width="100%" border="0"  cellpadding="5" cellspacing="0">
	<tr>
	<td width="50%" >
	
	</td>
	<td width="" align=right><? echo turnpage2($pagesize,$rstotal);?></td>
	</tr>
  </table>
  </form>
  
</div>
<?include('inc_foot.php');?>
</body>
</html>